package com.wofish.web.controller.member;

import java.util.List;

import com.wofish.member.domain.MemberPointRecord;
import com.wofish.member.service.IMemberPointRecordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wofish.common.annotation.Log;
import com.wofish.common.enums.BusinessType;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.utils.poi.ExcelUtil;

/**
 * 会积分使用记录 信息操作处理
 * 
 * @author wofish
 * @date 2019-05-21
 */
@Controller
@RequestMapping("/member/memberPointRecord")
public class MemberPointRecordController extends BaseController {
    private String prefix = "member/memberPointRecord";
	
	@Autowired
	private IMemberPointRecordService memberPointRecordService;
	
	@RequiresPermissions("member:memberPointRecord:view")
	@GetMapping()
	public String memberPointRecord() {
	    return prefix + "/memberPointRecord";
	}
	
	/**
	 * 查询会积分使用记录列表
	 */
	@RequiresPermissions("member:memberPointRecord:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MemberPointRecord memberPointRecord) {
		startPage();
        List<MemberPointRecord> list = memberPointRecordService.selectMemberPointRecordList(memberPointRecord);
		return getDataTable(list);
	}
	



	/**
	 * 导出会积分使用记录列表
	 */
	@RequiresPermissions("member:memberPointRecord:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberPointRecord memberPointRecord) {
    	List<MemberPointRecord> list = memberPointRecordService.selectMemberPointRecordList(memberPointRecord);
        ExcelUtil<MemberPointRecord> util = new ExcelUtil<MemberPointRecord>(MemberPointRecord.class);
        return util.exportExcel(list, "memberPointRecord");
    }
	
	/**
	 * 新增会积分使用记录
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存会积分使用记录
	 */
	@RequiresPermissions("member:memberPointRecord:add")
	@Log(title = "会积分使用记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MemberPointRecord memberPointRecord) {
		return toAjax(memberPointRecordService.insertMemberPointRecord(memberPointRecord));
	}

	/**
	 * 修改会积分使用记录
	 */
	@GetMapping("/edit/{recordId}")
	public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap) {
		MemberPointRecord memberPointRecord = memberPointRecordService.selectMemberPointRecordById(recordId);
		mmap.put("memberPointRecord", memberPointRecord);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存会积分使用记录
	 */
	@RequiresPermissions("member:memberPointRecord:edit")
	@Log(title = "会积分使用记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MemberPointRecord memberPointRecord) {
		return toAjax(memberPointRecordService.updateMemberPointRecord(memberPointRecord));
	}
	
	/**
	 * 删除会积分使用记录
	 */
	@RequiresPermissions("member:memberPointRecord:remove")
	@Log(title = "会积分使用记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(memberPointRecordService.deleteMemberPointRecordByIds(ids));
	}
	
}
